package top.yueshushu.learn.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.yueshushu.learn.business.UserBusiness;
import top.yueshushu.learn.common.ResultCode;
import top.yueshushu.learn.mode.ro.UserRo;
import top.yueshushu.learn.response.OutputResult;

import javax.annotation.Resource;

/**
 * <p>
 * 登录用户表 我是自定义的
 * </p>
 *
 * @author 岳建立
 * @date 2022-01-02
 */
@RestController
@RequestMapping("/user")
@Api("用户信息")
public class UserController  {
    @Resource
    private UserBusiness userBusiness;

    @PostMapping("/login")
    @ApiOperation("用户登录信息")
    public OutputResult login(@RequestBody UserRo userRo) {
        // 对数据进行 check
        if (!StringUtils.hasText(userRo.getAccount())) {
            return OutputResult.buildAlert(ResultCode.INVALID_PARAM);
        }
        if (!StringUtils.hasText(userRo.getPassword())) {
            return OutputResult.buildAlert(ResultCode.INVALID_PARAM);
        }
        return userBusiness.login(userRo);
    }
}
